package com.qf.android.sport.adapter;

import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.qf.android.sport.R;

import java.util.List;

/**
 * Created by weizz on 2016/12/15.
 */

public class PopListAdapter extends BaseAdapter {

    private List<String> list;
    private LayoutInflater inflater;
    private String currTitle;
    private Context context;
    public PopListAdapter(List<String> list, Context context,String title) {
        this.list = list;
        this.inflater = LayoutInflater.from(context);
        this.currTitle = title;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView = inflater.inflate(R.layout.layout_popuplist_item,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.textView.setText(list.get(position));
        if (currTitle.equals(list.get(position))){
            holder.textView.setTextColor(Color.RED);
            holder.textView.setBackground(context.getResources().getDrawable(R.mipmap.abc_popup_background_mtrl_mult));
        }
        return convertView;
    }

    public class ViewHolder{
        private TextView textView;

        public ViewHolder(View convertView) {
            this.textView = (TextView) convertView.findViewById(R.id.popListItem);
        }
    }
}
